package com.haiertvbic.tvnow.widget;

import java.util.Timer;
import java.util.TimerTask;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.widget.BaseAdapter;

import com.haiertvbic.tvnow.model.ProgramBean;
import com.haiertvbic.tvnow.network.EPGWeb;
import com.haiertvbic.tvnow.util.Constant;
import com.haiertvbic.tvnow.util.SLog;

public class MyProgress {
	protected static final String TAG = "MyProgress";
	public int progress;
	private BaseAdapter adapter;
	private Context context;
	private String cid;
	private Handler handler = new Handler() {
		public void handleMessage(android.os.Message msg) {
			switch (msg.what) {
			case 11:
				progress = (Integer) msg.obj;
				adapter.notifyDataSetChanged();
				break;

			default:
				break;
			}
		};
	};

	public MyProgress(BaseAdapter adapter, Context context, String cid) {
		super();
		this.adapter = adapter;
		this.context = context;
		this.cid = cid;
		getPic();
	}

	// 更换进度的

	private void getPic() {
		if (Constant.PROGRESS_TT != null) {
			Constant.PROGRESS_TT.schedule(new TimerTask() {
				private int progress;

				@Override
				public void run() {
					SLog.d(TAG, "执行获取进度条任务的频道号是==" + cid);
					ProgramBean pro = EPGWeb.getCurrentProgram(context, cid);
					if (pro != null) {
						progress = PIPCache.getProgress(pro);
						Message msg = Message.obtain();
						msg.what = 11;
						msg.obj = progress;
						handler.sendMessage(msg);
					} else {
						SLog.d(TAG, "pro为空=");

					}
				}
			}, 0, 1000 * 30);
		}

	}
}
